# 采用Nginx稳定版本
#FROM nginx:stable-alpine
#
#MAINTAINER sweet3c
#
#ENV TIMEZONE            Asia/Shanghai
#
#ARG PHP_VERSION=7
#ARG PHP_FRAMEWORK=laravel

# 定义Nginx及虚拟机配置文件，可根据实际情况修改路径
#ARG NGINX_CONF_DIR=conf/nginx
#ARG FPM_CONF=conf/php-fpm/php-fpm.conf
#ARG FPM_WWW_CONF=conf/php-fpm/www.conf
#ARG PHP_CONF=conf/php/php.ini

# 设置软件源为清华镜像
#RUN if [ "${PHP_VERSION}" = "7" ] ; \
#    then \
#      echo 'http://mirrors.aliyun.com/alpine/latest-stable/community/' >  /etc/apk/repositories && \
#      echo 'http://mirrors.aliyun.com/alpine/latest-stable/main/'      >> /etc/apk/repositories ; \
#    else \
#      echo 'http://mirrors.aliyun.com/alpine/v3.8/community/'      > /etc/apk/repositories && \
#      echo 'http://mirrors.aliyun.com/alpine/v3.8/main/'      >> /etc/apk/repositories ; \
#    fi

#RUN echo 'http://mirrors.aliyun.com/alpine/v3.7/community/'      > /etc/apk/repositories && \
#    echo 'http://mirrors.aliyun.com/alpine/v3.7/main/'      >> /etc/apk/repositories

# 设置好系统时区为东八区 安装系统运行需要的软件，可根据实际情况增删
#RUN apk update && apk add tzdata \
#    && cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
#    && apk del tzdata \
#    && apk add bash wget curl autoconf vim git supervisor gcc g++ openssl-dev

# 安装PHP及常用扩展，可根据实际情况增删
#RUN apk add php${PHP_VERSION}-fpm \
#    php${PHP_VERSION}-common \
#    php${PHP_VERSION}-dev \
##    php${PHP_VERSION}-xdebug \
#    php${PHP_VERSION}-pdo \
#    php${PHP_VERSION}-pdo_mysql \
##    php${PHP_VERSION}-mysqlnd \
#    php${PHP_VERSION}-mysqli \
#    php${PHP_VERSION}-mcrypt \
##    php${PHP_VERSION}-mbstring \
#    php${PHP_VERSION}-ctype \
#    php${PHP_VERSION}-zlib \
#    php${PHP_VERSION}-gd \
#    php${PHP_VERSION}-exif \
#    php${PHP_VERSION}-intl \
#    php${PHP_VERSION}-sqlite3 \
##    php${PHP_VERSION}-pdo_pgsql \
##    php${PHP_VERSION}-pgsql \
#    php${PHP_VERSION}-xml \
#    php${PHP_VERSION}-xsl \
#    php${PHP_VERSION}-curl \
#    php${PHP_VERSION}-openssl \
#    php${PHP_VERSION}-iconv \
#    php${PHP_VERSION}-json \
#    php${PHP_VERSION}-phar \
#    php${PHP_VERSION}-soap \
#    php${PHP_VERSION}-dom \
#    php${PHP_VERSION}-zip \
##    php${PHP_VERSION}-session \
#    php${PHP_VERSION}-imap \
#    php${PHP_VERSION}-opcache \
#    php${PHP_VERSION}-pear \
#    php${PHP_VERSION}-sockets \
#    php${PHP_VERSION}-pcntl \
#    php${PHP_VERSION}-posix \
#    php${PHP_VERSION}-sysvmsg \
#    php${PHP_VERSION}-sysvshm \
#    php${PHP_VERSION}-sysvsem \
##    php${PHP_VERSION}-redis \
# 	&& rm -rf /var/cache/apk/*
    
# 覆盖Nginx及FPM配置文件
#RUN rm -rf /etc/nginx/nginx.conf \
#    && rm -rf /etc/nginx/conf.d/default.conf \
#    && rm -rf /etc/php${PHP_VERSION}/php-fpm.conf \
#    && rm -rf /etc/php${PHP_VERSION}/php-fpm.d/www.conf \
#    && rm -rf /etc/php${PHP_VERSION}/php.ini

#ADD ${NGINX_CONF_DIR}/nginx.conf /etc/nginx/nginx.conf
#ADD ${NGINX_CONF_DIR}/${PHP_FRAMEWORK}.conf /etc/nginx/conf.d/default.conf
#ADD ${FPM_CONF} /etc/php${PHP_VERSION}/php-fpm.conf
#ADD ${FPM_WWW_CONF} /etc/php${PHP_VERSION}/php-fpm.d/www.conf
#ADD ${PHP_CONF} /etc/php${PHP_VERSION}/php.ini

# 复制 supervisor 配置文件
#RUN rm -rf /etc/supervisord.conf
#ADD conf/supervisord.conf /etc/supervisor/supervisord.conf

# Set environments
#RUN sed -i "s|__PHP_VERSION__|${PHP_VERSION}|" /etc/nginx/conf.d/default.conf && \
#	sed -i "s|__PHP_VERSION__|${PHP_VERSION}|" /etc/php${PHP_VERSION}/php-fpm.conf && \
#	sed -i "s|__PHP_VERSION__|${PHP_VERSION}|" /etc/php${PHP_VERSION}/php-fpm.d/www.conf && \
#	sed -i "s|__PHP_VERSION__|${PHP_VERSION}|" /etc/php${PHP_VERSION}/php.ini && \
#	sed -i "s|__PHP_VERSION__|${PHP_VERSION}|" /etc/supervisor/supervisord.conf && \
#	sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php${PHP_VERSION}/php.ini

# Add-Composer
#ADD scripts/composer /usr/bin/composer

#RUN chmod a+x /usr/bin/composer \
#    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 装载启动脚本
#ADD scripts/start.sh /start.sh
#RUN chmod a+x /start.sh

# 将虚拟机 root 路径暴露成卷
# 方便宿主机和容器实现目录共享
# 该值为虚拟机配置中的 root 路径，这里默认为 /var/www
# 可根据实际虚拟机配置进行修改
#VOLUME /var/www

# 执行一些必要的 bash 命令来确保系统配置正常运行，可根据实际情况调整
# RUN adduser www-data -G www-data -s /sbin/nologin -D www-data

#EXPOSE 80
#CMD ["/start.sh"]


#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
#    && apk update \
#	&& apk add --no-cache libmcrypt-dev freetype-dev libjpeg-turbo-dev \
#	&& docker-php-ext-install mcrypt pdo_mysql \
#	&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \
#    && docker-php-ext-install -j$(nproc) gd \
#	&& mkdir -p /usr/src/php/ext/redis \
#    && curl -L https://github.com/phpredis/phpredis/archive/3.1.6.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
#    && echo 'redis' >> /usr/src/php-available-exts \
#    && docker-php-ext-install redis

#
#ENV PHPIZE_DEPS=autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c
#ENV PHP_INI_DIR=/usr/local/etc/php
#
#RUN /bin/sh -c mkdir -p $PHP_INI_DIR/conf.d
#
#ENV PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2
#ENV PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2
#
#RUN /bin/sh -c set -xe; \
#apk add --no-cache --virtual .fetch-deps gnupg wget; \
#mkdir -p /usr/src; cd /usr/src; wget -O php.tar.xz "$PHP_URL"; \
#if [ -n "$PHP_SHA256" ]; then \
#  echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
#fi; \
#if [ -n "$PHP_MD5" ]; then \
#  echo "$PHP_MD5 *php.tar.xz" | md5sum -c -; \
#fi; \
#if [ -n "$PHP_ASC_URL" ]; then \
#  wget -O php.tar.xz.asc "$PHP_ASC_URL"; export GNUPGHOME="$(mktemp -d)"; \
#  for key in $GPG_KEYS; do \
#    gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
#  done; \
#  gpg --batch --verify php.tar.xz.asc php.tar.xz; \
#  command -v gpgconf > /dev/null && gpgconf --kill all; \
#  rm -rf "$GNUPGHOME"; \
#fi; \
#apk del .fetch-deps
#
#RUN /bin/sh -c set -xe && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS coreutils curl-dev libedit-dev libressl-dev libxml2-dev sqlite-dev \
#    && export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
#    && docker-php-source extract \
#    && cd /usr/src/php \
#    && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
#    && ./configure --build="$gnuArch" --with-config-file-path="$PHP_INI_DIR" --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" --enable-option-checking=fatal --with-mhash \
#      --enable-ftp --enable-mbstring --enable-mysqlnd --with-curl --with-libedit \
#      --with-openssl --with-zlib $(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') $PHP_EXTRA_CONFIGURE_ARGS \
#    && make -j "$(nproc)" \
#    && make install \
#    && { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
#    && make clean \
#    && cp -v php.ini-* "$PHP_INI_DIR/" \
#    && cd / \
#    && docker-php-source delete \
#    && runDeps="$( scanelf --needed --nobanner --format '%n#p' --recursive /usr/local | tr ',' '\n' | sort -u | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' )" \
#    && apk add --no-cache --virtual .php-rundeps $runDeps \
#    && apk del .build-deps \
#    && pecl update-channels \
#    && rm -rf /tmp/pear ~/.pearrc
#
#/bin/sh -c set -x     && addgroup -g 101 -S nginx    \
#     && adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx    \
#     && apkArch="$(cat /etc/apk/arch)"  \
#       && nginxPackages="         nginx=${NGINX_VERSION}-r${PKG_RELEASE}         nginx-module-xslt=${NGINX_VERSION}-r${PKG_RELEASE}         nginx-module-geoip=${NGINX_VERSION}-r${PKG_RELEASE}         nginx-module-image-filter=${NGINX_VERSION}-r${PKG_RELEASE}         nginx-module-perl=${NGINX_VERSION}-r${PKG_RELEASE}         nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-r${PKG_RELEASE}     "   \
#      && apk add --no-cache --virtual .checksum-deps         openssl     && case "$apkArch" in         x86_64|aarch64)             set -x             && KEY_SHA512="e7fa8303923d9b95db37a77ad46c68fd4755ff935d0a534d26eba83de193c76166c68bfe7f65471bf8881004ef4aa6df3e34689c305662750c0172fca5d8552a *stdin"          \
#       && wget -O /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub         \
#        && if [ "$(openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout | openssl sha512 -r)" = "$KEY_SHA512" ]; then     echo "key verification succeeded!";  \
#        mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/;             else         \
#            echo "key verification failed!";                 exit 1;     \
#            fi            \
#     && apk add -X "https://nginx.org/packages/mainline/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages   ;; *)    set -x  && tempDir="$(mktemp -d)"         \
#        && chown nobody:nobody $tempDir         \
#        && apk add --no-cache --virtual .build-deps          \
#           gcc                 libc-dev                 make            \
#         openssl-dev                 pcre2-dev                 zlib-dev           \
#          linux-headers                 libxslt-dev                 gd-dev           \
#          geoip-dev                 perl-dev                 libedit-dev                 bash    \
#                 alpine-sdk                 findutils       \
#          && su nobody -s /bin/sh -c "                 export HOME=${tempDir}            \
#         && cd ${tempDir}   \
#     && curl -f -O https://hg.nginx.org/pkg-oss/archive/${NGINX_VERSION}-${PKG_RELEASE}.tar.gz        \
#             && PKGOSSCHECKSUM=\"b0ed109a820a2e8921f313d653032b8e70d3020138d634039ebb9194dc3968493f6eb4d85bdbf18d2aea7229deddb98ca0f1d9825defcc5af45f68ee37845232 *${NGINX_VERSION}-${PKG_RELEASE}.tar.gz\"          \
#           && if [ \"\$(openssl sha512 -r ${NGINX_VERSION}-${PKG_RELEASE}.tar.gz)\" = \"\$PKGOSSCHECKSUM\" ]; then           \
#              echo \"pkg-oss tarball checksum verification succeeded!\";         \
#            else              \
#           echo \"pkg-oss tarball checksum verification failed!\";            \
#             exit 1;          \
#           fi              \
#       && tar xzvf ${NGINX_VERSION}-${PKG_RELEASE}.tar.gz     \
#                && cd pkg-oss-${NGINX_VERSION}-${PKG_RELEASE}        \
#             && cd alpine          \
#           && make all      \
#               && apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk    \
#                 && abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz  "       \
#          && cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/         \
#        && apk del .build-deps      \
#           && apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages  ;;   esac    \
#     && apk del .checksum-deps     && if [ -n "$tempDir" ]; then rm -rf "$tempDir";  \
#    fi     && if [ -n "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub;  \
#    fi    \
#     && if [ -n "/etc/apk/keys/nginx_signing.rsa.pub" ]; then rm -f /etc/apk/keys/nginx_signing.rsa.pub; fi    \
#     && apk add --no-cache --virtual .gettext gettext     && mv /usr/bin/envsubst /tmp/    \
#         && runDeps="$(         scanelf --needed --nobanner /tmp/envsubst             | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }'             | sort -u             | xargs -r apk info --installed             | sort -u     )"   \
#      && apk add --no-cache $runDeps  \
#       && apk del .gettext  \
#        && mv /tmp/envsubst /usr/local/bin/   \
#      && apk add --no-cache tzdata  \
#       && apk add --no-cache curl ca-certificates   \
#      && ln -sf /dev/stdout /var/log/nginx/access.log  \
#       && ln -sf /dev/stderr /var/log/nginx/error.log     && mkdir /docker-entrypoint.d

